﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using ThresholdAssistant.DataContract.Result;
using ThresholdAssistant.WebAPI.Models;
using ThresholdAssistant.WebAPI.Service;

namespace ThresholdAssistant.WebAPI.Controllers
{
    /// <summary>
    /// 参数控制器
    /// </summary>
    [Route("api/config")]
    public class ConfigController : BaseController
    {
        /// <summary>
        /// 阈值服务
        /// </summary>
        public ConfigService ConfigService { get; set; }

        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("get-list")]
        [AllowAnonymous]
        public async Task<ContractResult<IEnumerable<ConfigData>>> GetListAsync(GetThresholdListParam param)
        {
            return await ConfigService.GetListAsync(param);
        }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("init")]
        [AllowAnonymous]
        public async Task<ContractResult<bool>> InitAsync(GetThresholdListParam param)
        {
            return await ConfigService.InitAsync(param);
        }

        /// <summary>
        /// 单个
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("get-info")]
        [AllowAnonymous]
        public async Task<ContractResult<ConfigData>> GetInfoAsync(GetThresholdInfoParam param)
        {
            return await ConfigService.GetInfoAsync(param.Id);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("update")]
        [AllowAnonymous]
        public async Task<ContractResult> UpdateAsync(UpdateConfigParam param)
        {
            return await ConfigService.UpdateAsync(param);
        }
    }
}
